#!/usr/bin/python
'''
Created on Feb 1, 2011

@author: mikeg
'''
import wx

ID_QUIT = 1

class SubmenuExample(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, size=(350, 250))
        menubar = wx.MenuBar()
        
        file = wx.Menu()
        file.Append(-1, '&New')
        file.Append(-1, '&Open')
        file.Append(-1, '&Save')
        file.AppendSeparator()
        
        imp = wx.Menu()
        imp.Append(-1, 'Import newsfeed list...')
        imp.Append(-1, 'Import bookmarks...')
        imp.Append(-1, 'Import mail...')
        
        file.AppendMenu(-1, 'I&mport', imp)
        
        quit = wx.MenuItem(file, ID_QUIT, '&Quit\tCtrl+Q')
        file.AppendItem(quit)
        
        self.Bind(wx.EVT_MENU, self.OnQuit, id=ID_QUIT)
        
        menubar.Append(file, '&File')
        self.SetMenuBar(menubar)
        
        self.Centre()
        self.Show(True)
        
    def OnQuit(self, event):
        self.Close()
        
class Size(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, size=(250,200))
        
        self.Show(True)
        
class Center(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title)
        
        self.Center()
        self.Show(True)
        
class LeftPanel(wx.Panel):
    def __init__(self, parent, id):
        wx.Panel.__init__(self, parent, id, style=wx.BORDER_SUNKEN)
        
        self.text = parent.GetParent().rightPanel.text
        
        button1 = wx.Button(self, -1, '+', (10, 10))
        button2 = wx.Button(self, -1, '-', (10, 60))
        
        self.Bind(wx.EVT_BUTTON, self.OnPlus, id=button1.GetId())
        self.Bind(wx.EVT_BUTTON, self.OnMinus, id=button2.GetId())
        
    def OnPlus(self, event):
        value = int(self.text.GetLabel())
        value = value + 1
        self.text.SetLabel(str(value))
        
    def OnMinus(self, event):
        value = int(self.text.GetLabel())
        value = value - 1
        self.text.SetLabel(str(value))
        
class RightPanel(wx.Panel):
    def __init__(self, parent, id):
        wx.Panel.__init__(self, parent, id, style=wx.BORDER_SUNKEN)
        self.text = wx.StaticText(self, -1, '0', (40, 60))
        
class Communicate(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, size=(280, 200))
        
        panel = wx.Panel(self, -1)
        self.rightPanel = RightPanel(panel, -1)
        
        leftPanel = LeftPanel(panel, -1)
        
        hbox = wx.BoxSizer()
        hbox.Add(leftPanel, 1, wx.EXPAND | wx.ALL, 5)
        hbox.Add(self.rightPanel, 1, wx.EXPAND | wx.ALL, 5)
        
        panel.SetSizer(hbox)
        self.Centre()
        self.Show(True)
        
class SimpleMenu(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, size=(250, 150))
        
        menubar = wx.MenuBar()
        file = wx.Menu()
        file.Append(-1, 'Quit', 'Quit application')
        menubar.Append(file, '&File')
        wat = wx.Menu()
        wat.Append(-1, 'trolled', 'lol')
        wat.Append(-1, 'problem', 'ujelly?')
        menubar.Append(wat, '&wat')
        self.SetMenuBar(menubar)
        
        self.Centre()
        self.Show(True)        

class Dockable(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title)

        menubar = wx.MenuBar(wx.MB_DOCKABLE)
        file = wx.Menu()
        edit = wx.Menu()
        view = wx.Menu()
        insr = wx.Menu()
        form = wx.Menu()
        tool = wx.Menu()
        help = wx.Menu()

        menubar.Append(file, '&File')
        menubar.Append(edit, '&Edit')
        menubar.Append(view, '&View')
        menubar.Append(insr, '&Insert')
        menubar.Append(form, '&Format')
        menubar.Append(tool, '&Tools')
        menubar.Append(help, '&Help')
        self.SetMenuBar(menubar)

        self.Centre()
        self.Show(True)

class MenuExample(wx.Frame):
    def __init__(self, parent, id, title, size=(250, 150)):
        wx.Frame.__init__(self, parent, id, title, size=(250, 150))
        menubar = wx.MenuBar()
        file = wx.Menu()
        quit = wx.MenuItem(file, 1, '&Quit\tCtrl+Q')
        file.AppendItem(quit)
        
        self.Bind(wx.EVT_MENU, self.OnQuit, id=1)
        
        menubar.Append(file, '&File')
        self.SetMenuBar(menubar)
        
        self.Centre()
        self.Show(True)
        
    def OnQuit(self, event):
        self.Close()
        
class MyPopupMenu(wx.Menu):
    def __init__(self, parent):
        wx.Menu.__init__(self)
        
        self.parent = parent
        
        minimize = wx.MenuItem(self, wx.NewId(), 'Minimize')
        self.AppendItem(minimize)
        self.Bind(wx.EVT_MENU, self.OnMinimize, id=minimize.GetId())
        
        close = wx.MenuItem(self, wx.NewId(), 'Close')
        self.AppendItem(close)
        self.Bind(wx.EVT_MENU, self.OnClose, id=close.GetId())
        
    def OnMinimize(self, event):
        self.parent.Iconize()
        
    def OnClose(self, event):
        self.parent.Close()

class ContextMenu(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, size=(250, 150))
        
        self.Bind(wx.EVT_RIGHT_DOWN, self.OnRightDown)
        
        self.Center()
        self.Show()
        
    def OnRightDown(self, event):
        self.PopupMenu(MyPopupMenu(self), event.GetPosition())
        
app = wx.App()
#frame = ContextMenu(None, -1, 'context menu')
#SubmenuExample(None, -1, 'Submenu')
#MenuExample(None, -1, '')
#Dockable(None, -1, 'Dockable menubar')
#SimpleMenu(None, -1, 'simple menu example')
#Communicate(None, -1, 'widgets communicate')
#Center(None, -1, 'Center')
#Size(None, -1, 'Size')
app.MainLoop()

if __name__ == '__main__':
    pass